﻿#include "widget.h"

#include <butterfly.h>

#include <QApplication>
#include <QDesktopWidget>
#include <QPushButton>
#include <QRandomGenerator>

#include "ui_widget.h"
Widget::Widget(QWidget* parent) : QWidget(parent), ui(new Ui::Widget) {
  ui->setupUi(this);

  setWindowFlag(Qt::FramelessWindowHint);  //去边框
  // setAttribute(Qt::WA_TranslucentBackground);
  // //窗口透明，会被鼠标击穿，使窗口最小化
  showMaximized();  //最大化
  QPalette palette;
  //设置主窗口背景颜色
  palette.setColor(QPalette::Window, QColor(255, 150, 30));
  this->setPalette(palette);
  //创建蝴蝶飞行效果
  for (int i = 0; i < 50; ++i) {
    butterfly* win = new butterfly(this);  //嵌入父widget中
    win->move(
        QRandomGenerator::global()->bounded(this->width()),
        QRandomGenerator::global()->bounded(this->height()));  //设置默认位置
    win->show();
  }

  //创建关闭按钮
  QPushButton* button = new QPushButton(this);
  button->setFixedSize(100, 50);
  button->setText(tr("CLOSE"));
  // button->setFlat(true);

  QDesktopWidget* desk1 = QApplication::desktop();
  button->move(desk1->screenGeometry().right() - 100,
               desk1->screenGeometry().bottom() - 100);
  button->setStyleSheet(
      "QPushButton{background-color:rgba(15,15,15,15);font: 75 16pt ; "
      "font-size:16px;}");
  connect(button, &QPushButton::clicked, this, &QWidget::close);
  button->show();
}
Widget::~Widget() { delete ui; }
